package sjtu.ist.warehouse4ws.dao;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import sjtu.ist.warehouse4ws.model.Permission;
import sjtu.ist.warehouse4ws.model.Permissionresources;
import sjtu.ist.warehouse4ws.model.Rolepermissions;


public class PermissionresourcesDaoHibernate extends BaseDaoHibernate<Permissionresources> implements PermissionresourcesDao{

	@Override
	public Integer save(Permissionresources permissionresources) {
		// TODO Auto-generated method stub
		getHibernateTemplate().setFlushMode(HibernateTemplate.FLUSH_EAGER);
		return (Integer)getHibernateTemplate().save(permissionresources) ;
	}
	@Override
	public List findById(String id) {
		// TODO Auto-generated method stub
		//return (List<Permissionresources>)getHibernateTemplate().find("from Permissionresources r where r.permissionid='"+id+"'");
		return getSession().createSQLQuery("select permissionresources.* from permissionresources where permissionresources.permissionid='"+id+"'").addEntity(Permissionresources.class).list();
	}
	
	@Override
	public List<String> findResourcesByPermissionid(String id) {
		// TODO Auto-generated method stub
		//System.out.print("findResourcesByPermissionid");
		//return (List<String>)getHibernateTemplate().find("select resourceid from Permissionresources r where r.permissionid='"+id+"'");
		return (List<String>)getSession().createSQLQuery("select resourceid from permissionresources where permissionresources.permissionid='"+id+"'").list();
	}
	

}
